# -*- coding: utf-8 -*-
#enemies here!!!

import pyglet
import math

from objects import *

class Enemy(GameObject):
    def __init__(self, x, y, image, batch=None):
        self.sprite = pyglet.sprite.Sprite(image, x=x, y=y, batch=batch)
        super(Enemy, self).__init__()

    def update(self, dt):
        deltax = self.sprite.x-World.player.sprite.x
        deltay = self.sprite.y-World.player.sprite.y
        factor = self.velocity/math.sqrt(deltax*deltax + deltay*deltay)
        dx = -factor*deltax
        dy = -factor*deltay
        self.sprite.x += dx
        self.sprite.y += dy

        lastrect = self.rect
        self.rect = self.get_rect()
        for building in World.buildings:
            if collision(self.rect, building.rect):
                self.keep_out_of(building.rect, lastrect)
                print self.rect, lastrect

class OndaKalle(Enemy):
    def __init__(self, x,y,batch=None):
        image = pyglet.resource.image("solider_idle.png")

        self.velocity = 5

        super(OndaKalle, self).__init__(x,y,image,batch)

    